<?php
namespace app\api\model;

use think\facade\Db;
use think\Model;

class User extends Model
{
    //表名
    static $tableName = 'user';
    //接受参数 入库参数
    public static function param($request)
    {
        $data['id'] = $request->post('id') ?? null;
        $data['name'] = $request->post('name') ?? null;
        $data['age'] = $request->post('age') ?? null;
        $data['like'] = $request->post('like') ?? null;
        $data['sex'] = $request->post('sex') ?? null;

        return $data;
    }

    //添加数据
    public static function insertDatas($data)
    {
        $data['create_time']=date('Y-m-d h:i:s');
        $data['update_time']=date('Y-m-d h:i:s');
        $res = Db::table(self::$tableName)->insert($data);
        if(!$res){
            return false;
        }
        return true;
    }
    public function profile()
    {
        return $this->hasOne(Scores::class,'user_id');
    }

    //删除用户信息
    public static function delUserMsg($id){
        $res = Db::table(self::$tableName)->delete(['id'=>$id]);
        if(!$res){
            return false;
        }
        return true;
    }

    public static function upDatas($data,$id){
        $data['create_time']=date('Y-m-d h:i:s');
        $data['update_time']=date('Y-m-d h:i:s');
        $res = Db::table(self::$tableName)->where(['id'=>$id])->update($data);
        if(!$res){
            return false;
        }
        return true;
    }
}